package com.bjsasc.testgreendao;

import android.content.Context;

import com.bjsasc.testgreendao.entity.Song;
import com.bjsasc.testgreendao.entity.Student;
import com.bjsasc.testgreendao.greendao.DaoSession;
import com.bjsasc.testgreendao.greendao.DaoSessionManager;
import com.bjsasc.testgreendao.greendao.SongDao;
import com.bjsasc.testgreendao.greendao.StudentDao;

import java.util.Date;


/**
 * Created by XinQing on 2018/3/20.
 */

public class TestGreenDao {

    public void testGreenDao(Context context) {

        //获取Song这张表的操作类SongDao
        DaoSession daoSession = DaoSessionManager.getInstance()
                .getDaoSession(context);
        SongDao songDao = daoSession.getSongDao();

        //创建一个对象
        Song song = new Song();
        song.setSingerCode(111);
        song.setCreateTime(new Date());


        //增加
        songDao.insert(song);

        //改
        song.setSingerName("miss08");
        songDao.update(song);

        //查
        Song query = songDao.queryBuilder().where(SongDao.Properties.SingerCode.eq(111))
                .list().get(0);

        //删
//        songDao.delete(song);

        StudentDao studentDao = daoSession.getStudentDao();
        Student student = new Student(null,"小明",11,1L);
        studentDao.insert(student);
    }


}
